package cn.lijiajia3515.cairo.auth.framework.security.web.authentication;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.authentication.event.LogoutSuccessEvent;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class CairoLogAuthenticationFailedListener {


	@EventListener(AuthenticationSuccessEvent.class)
	public void success(AuthenticationSuccessEvent event) {
		log.debug("auth success: auth: {}", event.getAuthentication());
	}

	@EventListener(AbstractAuthenticationFailureEvent.class)
	public void success(AbstractAuthenticationFailureEvent event) {
		log.debug("auth failed auth: {} ex: {}: message: {}", event.getAuthentication(), event.getException().getClass(), event.getException().getMessage());
	}

	@EventListener(LogoutSuccessEvent.class)
	public void logout(LogoutSuccessEvent event) {
		log.debug("auth logout auth: {}", event.getAuthentication());
	}

}
